<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$(
								'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
								'.form').iTextClear();
					});
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<!-- DATATABLES CSS END -->

<h1 class="page-title">考核标准设定 - ${title}</h1>
<div class="container_12 clearfix leading">
	<div class="side grid_12 leading">
		<form class="form has-validation" id="post_form">
			<s:if test="#request.examQualStandardSet.id > 0">
				<input type="hidden" name="examQualStandardSet.id"
					value="${examQualStandardSet.id}" />
			</s:if>
			<input type="hidden" name="examQualStandardSet.organization.id"
				value="${examQualStandardSet.organization.id}" />
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">考核标准 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="name" name="examQualStandardSet.name"
						value="${examQualStandardSet.name}" required="required"
						placeholder="请输入考核标准" />
				</div>
			</div>
			<div class="clearfix">
				<label for="form-name" class="form-label">分数区间 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="scoreStart"
						name="examQualStandardSet.scoreStart"
						value="${examQualStandardSet.scoreStart}" required="required"
						placeholder="请输入0-100的分数下限" /> <input type="text" id="scoreEnd"
						name="examQualStandardSet.scoreEnd"
						value="${examQualStandardSet.scoreEnd}" required="required"
						placeholder="请输入0-100的分数上限" />
				</div>
			</div>
			<div class="clearfix">
				<label class="form-label" for="form-textarea">备注</label>
				<div class="form-input form-textarea">
					<span class="iTextClearButtonContainer"><textarea
							placeholder="备注" rows="5" name="examQualStandardSet.remark">${examQualStandardSet.remark}</textarea><a
						class="iTextClearButton" style="display: none;"></a></span>
				</div>
			</div>
			<div class="form-action clearfix">
				<button class="button" type="button" onclick="checkForm()">
					<s:if test="#request.examQualStandardSet.id > 0">修改</s:if>
					<s:else>添加</s:else>
				</button>
				<button class="button" type="reset">重置</button>
				<a class="button" href="javascript:void(0)"
					onclick="javascript:history.back()"><span
					style="background: url(${ctx}/images/img/arrow_undo.png)"
					class="icon">&nbsp;</span>返回</a>
			</div>
		</form>
	</div>
</div>
<div class="clear"></div>
<script type="text/javascript">
	function checkForm() {
		if ($("#name").val() == null) {
			alert("请填写考核标准");
			return;
		}
		if ($("#scoreStart").val() == null
				|| $("#scoreStart").val().trim() == ""
				|| isNaN($("#scoreStart").val())
				|| parseFloat($("#scoreStart").val().trim()) < 0 || parseFloat($("#scoreStart").val().trim()) > 100 ) {
			alert("请输入0-100的分数下限");
			return;
		}
		if ($("#scoreEnd").val() == null || $("#scoreEnd").val().trim() == ""
				|| isNaN($("#scoreEnd").val())
				|| parseFloat($("#scoreEnd").val().trim()) < 0 || parseFloat($("#scoreEnd").val().trim()) > 100) {
			alert("请输入0-100的分数上限");
			return;
		}
		
		if(parseFloat($("#scoreStart").val().trim()) >= parseFloat($("#scoreEnd").val().trim())){
			alert("强制分页分数区间设定异常，下限不能大于上限,请重新输入");
			return;
		}
		
		//检测数据有效性
		var url = "${ctx}/exam/validate_standscore.xhtml";
		var availability = true;
		$.ajax(url,
		{
			type : "POST",
			async:false,
			data : {"organizationId":eval("${examQualStandardSet.organization.id}"),
				"st":parseFloat($("#scoreStart").val().trim()),
				"se":parseFloat($("#scoreEnd").val().trim()),
				"i":eval("${examQualStandardSet.id}")},
			dataType : "html",
			cache : false,
			success : function(data) {
				if(data != null){
					var validate = eval("(" + data + ")");
					if(!validate.availability){
						availability = false;
					}
				}
			},
			error : function(XMLHttpRequest, textStatus,
					errorThrown) {
				alert('检测数据异常');
			},
			complete : function() {
			}
		});
		if(!availability){
			alert("输入的分数区间已经存在，请重新输入");
			return;
		}

		var url = "${ctx}/exam/post_qualstandset.xhtml";
		$.ajax(
						url,
						{
							type : "POST",
							data : $("#post_form").serialize(),
							dataType : "html",
							cache : false,
							success : function(a) {
                                window.location.href = "${ctx}/index.xhtml#exam/exam_list.xhtml?p=qual_standset";
							},
							error : function(XMLHttpRequest, textStatus,
									errorThrown) {
								alert('提交申请发生异常');
							},
							complete : function() {
							}
						});
	}
</script>
